using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Lottery.Data;

namespace Lottery
{
	/// <summary>
	/// Summary description for frmDrawingManager.
	/// </summary>
	public class frmDrawingManager : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid grdDrawing;
		private System.Windows.Forms.Button btnAddDrawing;
		private System.Windows.Forms.Button btnChangeDrawing;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDrawingManager()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.grdDrawing = new System.Windows.Forms.DataGrid();
			this.btnAddDrawing = new System.Windows.Forms.Button();
			this.btnChangeDrawing = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.grdDrawing)).BeginInit();
			this.SuspendLayout();
			// 
			// grdDrawing
			// 
			this.grdDrawing.DataMember = "";
			this.grdDrawing.Dock = System.Windows.Forms.DockStyle.Top;
			this.grdDrawing.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grdDrawing.Name = "grdDrawing";
			this.grdDrawing.ReadOnly = true;
			this.grdDrawing.Size = new System.Drawing.Size(600, 208);
			this.grdDrawing.TabIndex = 0;
			// 
			// btnAddDrawing
			// 
			this.btnAddDrawing.Location = new System.Drawing.Point(16, 224);
			this.btnAddDrawing.Name = "btnAddDrawing";
			this.btnAddDrawing.TabIndex = 1;
			this.btnAddDrawing.Text = "New";
			this.btnAddDrawing.Click += new System.EventHandler(this.btnAddDrawing_Click);
			// 
			// btnChangeDrawing
			// 
			this.btnChangeDrawing.Location = new System.Drawing.Point(104, 224);
			this.btnChangeDrawing.Name = "btnChangeDrawing";
			this.btnChangeDrawing.Size = new System.Drawing.Size(75, 24);
			this.btnChangeDrawing.TabIndex = 2;
			this.btnChangeDrawing.Text = "Change";
			this.btnChangeDrawing.Click += new System.EventHandler(this.btnChangeDrawing_Click);
			// 
			// frmDrawingManager
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(600, 405);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnChangeDrawing,
																		  this.btnAddDrawing,
																		  this.grdDrawing});
			this.HelpButton = true;
			this.Name = "frmDrawingManager";
			this.Text = "Drawing Manager";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.frmDrawingManager_Load);
			((System.ComponentModel.ISupportInitialize)(this.grdDrawing)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion


		private void btnAddDrawing_Click(object sender, System.EventArgs e)
		{
			frmAddDrawing addForm = new frmAddDrawing();
			addForm.ShowAdd();
		}

		private void frmDrawingManager_Load(object sender, System.EventArgs e)
		{
			grdDrawing.DataSource = DrawingManager.GetAllDrawings();		
		}

		private void btnChangeDrawing_Click(object sender, System.EventArgs e)
		{
			DataRow sRow = ((DataTable) grdDrawing.DataSource).Rows[grdDrawing.CurrentRowIndex];

			Combination c = new Combination(Convert.ToInt32(sRow[3]), Convert.ToInt32(sRow[4]), Convert.ToInt32(sRow[5]), Convert.ToInt32(sRow[6]), Convert.ToInt32(sRow[7]), Convert.ToInt32(sRow[8]));
			Drawing d = new Drawing(Convert.ToInt32(sRow[1]), DateTime.Parse(sRow[2].ToString()), c);
			frmAddDrawing addForm = new frmAddDrawing();
			addForm.ShowUpdate(d);	
		}
	}
}
